package controller.api;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;

import common.inter.ServicerCompanyInter;
import common.inter.ServiserInter;
import model.Company;
import service.ServicerCompanyService;

@Before(ServiserInter.class)
public class ApiServicerCompanyController extends BaseApiController {
	@Inject ServicerCompanyService servicerCompanyService ;

	public void save() {
		Company company = getModel(Company.class,"x");
		company.keep("name","simpleName","nameUsedBefore","latitude","longitude","address","industry","contacts","mobile");
	    renderJson(servicerCompanyService.save( company , getWxuser() ));
    }

	public void list() {
	    Kv kv = getParamKv() ;
	    kv.set("tsc.serviserId" , getWxuser().getCompanyId() );
	    Integer pageNumber = getParaToInt("pageNumber", 1);
	    Integer pageSize = getParaToInt("pageSize", 10);
	    set("page", servicerCompanyService.getApiPage( kv , pageNumber, pageSize));
	    renderJson();
	}
	
	@Before({ServicerCompanyInter.class})
	public void remove() {
		renderJson( servicerCompanyService.unbind(getServicerCompany()) );
	}
}
